<?php

Loader::using("ext::libs::restful::RESTfulClient");
Loader::using("Models::Entities::Recaladas");
Loader::using("Models::Entities::Archivos");

class RecaladasService extends RESTfulClient {

    public function GetAll() {
        $response = $this->call("/", "GET");
        $deserializer = $this->getDeserializer();
        return $deserializer->deserialize("Recaladas", $response);
    }

    public function GetDeleted() {
        $response = $this->call("/Eliminados/", "GET");
        $deserializer = $this->getDeserializer();
        return $deserializer->deserialize("Recaladas", $response);
    }

    public function GetByLinea($id) {
        $response = $this->call("/GetByLinea/$id", "GET");
        $deserializer = $this->getDeserializer();
        return $deserializer->deserialize("Recaladas", $response);
    }

    public function GetRecaladaPuerto($id) {
        $response = $this->call("/RecaladaPuerto/$id", "GET");
        $deserializer = $this->getDeserializer();
        return $deserializer->deserialize("RecaladasPuertos", $response);
    }

    public function GetArchivo($id) {
        $response = $this->call("/Archivo/$id", "GET");
        $deserializer = $this->getDeserializer();
        return $deserializer->deserialize("Archivos", $response);
    }
    
    public function GetArchivoById($id) {
        $response = $this->call("/ArchivoById/$id", "GET");
        $deserializer = $this->getDeserializer();
        return $deserializer->deserialize("Archivos", $response);
    }

    public function GetResitro($id) {
        $response = $this->call("/RegistroRecalada/$id", "GET");
        $deserializer = $this->getDeserializer();
        return $deserializer->deserialize("Recaladas", $response);
    }

    public function GetById($id) {
        $response = $this->call("/Recalada/$id", "GET");
        $deserializer = $this->getDeserializer();
        return $deserializer->deserialize("Recaladas", $response);
    }

    public function Update(Recaladas $recalada) {
        $serializer = $this->getSerializer();
        $data = $serializer->serialize($recalada);
        $this->call("/", "PUT", $data);
    }

    public function UpdateRegistroRecalada(RegistrosRecaladas $registroRecalada) {
        $serializer = $this->getSerializer();
        $data = $serializer->serialize($registroRecalada);
        $this->call("/RegistroRecalada", "PUT", $data);
    }

    public function UpdateRecaladaPuerto(RecaladasPuertos $recaladaPuerto) {
        $serializer = $this->getSerializer();
        $data = $serializer->serialize($recaladaPuerto);
        $this->call("/RecaladaPuerto", "PUT", $data);
    }

    public function CreateRecaladaPuerto(RecaladasPuertos $recaladaPuerto) {
        $serializer = $this->getSerializer();
        $data = $serializer->serialize($recaladaPuerto);
        $this->call("/RecaladaPuerto", "POST", $data);
    }

    /**
     *
     * @param Recaladas $recalada
     * @return Recaladas
     */
    public function Create(Recaladas $recalada) {
        $serializer = $this->getSerializer();
        $data = $serializer->serialize($recalada);
        $response = $this->call("/", "POST", $data);
        return $this->getDeserializer()->deserialize("Recaladas", $response);
    }

    public function CreateRegistro(RegistrosRecaladas $registro) {
        $serializer = $this->getSerializer();
        $data = $serializer->serialize($registro);
        $this->call("/RegistroRecalada", "POST", $data);
    }

    public function CreateArchivo(Archivos $archivo) {
        $serializer = $this->getSerializer();
        $data = $serializer->serialize($archivo);
        $this->call("/Archivo", "POST", $data);
    }

    public function Remove($id) {
        $this->call("/$id", "DELETE");
    }

    public function AgregarViaje(Viajes $viaje) {
        $data = $this->getSerializer()->serialize($viaje);
        $result = $this->call("/Viajes", "POST", $data);
        return $this->getDeserializer()->deserialize("Viajes", $result);
    }

    public function ActualizarViaje(Viajes $viaje) {
        $data = $this->getSerializer()->serialize($viaje);
        return $this->call("/Viajes", "PUT", $data);
    }

    public function GetViaje($id) {
        $result = $this->call("/$id");
        return $this->getDeserializer()->deserialize("Viajes", $result);
    }

    public function ListarPorEta($RangoInicial, $RangoFinal, $idAgencia) {
        $result = $this->call("/ByEta", "POST", json_encode(array(
                    "RangoInicial" => $RangoInicial,
                    "RangoFinal" => $RangoFinal,
                    "idAgencia" => $idAgencia,
                )));
        return $this->getDeserializer()->deserialize("Recaladas", $result);
    }
    
    public function EliminarArchivo($id) {
        $result = $this->call("/Archivo/$id", "DELETE");
        return $this->getDeserializer()->deserialize("boolean", $result);
    }

}

?>
